// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
const vscode = require('vscode');
const loadBook = require('./utils/loadBook')
const bookOptions = require('./utils/bookOptions')

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed

/**
 * @param {vscode.ExtensionContext} context
 */
function activate(context) {

	/** 加载文档事件 */
	let disposable_load = vscode.commands.registerCommand('vscode-mini-book.load', function () {
		// console.log('加载内容')
		const bookContent = loadBook.load()
		bookOptions.loadConfig()
		bookOptions.setBookContent(bookContent)
	});
	/** 老板键 */
	let disposable_bossKey = vscode.commands.registerCommand('vscode-mini-book.bossKey', function () {
		// console.log('老板键')
		bookOptions.bossKey()
	});
	/** 前进事件 */
	let disposable_goto = vscode.commands.registerCommand('vscode-mini-book.goTo', function () {
		// console.log('下一页')
		const isAuto = vscode.workspace.getConfiguration().get('vscodeMiniBook.auto')
		isAuto ? bookOptions.autoRead('start')  : bookOptions.goTo()
	});
	/** 后退事件 */
	let disposable_back = vscode.commands.registerCommand('vscode-mini-book.back', function () {
		// console.log('上一页')
		const isAuto = vscode.workspace.getConfiguration().get('vscodeMiniBook.auto')
		isAuto ? bookOptions.autoRead('stop')  : bookOptions.back()
	});
	/** 监听配置参数发生变化 */
	let watch_config = vscode.workspace.onDidChangeConfiguration(() => {
		console.log('配置发生变化！');
		bookOptions.changeConfig()
	})

	/** 事件统一注册 */
	context.subscriptions.push(
		disposable_load,
		disposable_bossKey,
		disposable_goto,
		disposable_back,
		watch_config
	);

}
exports.activate = activate;

// this method is called when your extension is deactivated
function deactivate() {
	vscode.window.showInformationMessage('Goodbay vscode-mini-book!');
}

module.exports = {
	activate,
	deactivate
}
